/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evangelion.core.controller;

import com.evangelion.core.bean.Seccione;
import com.evangelion.core.bean.Usuario;
import com.evangelion.web.filter.SecurityUtils;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Kellycasma
 */
@ManagedBean
@ViewScoped
public class InicioseccionController {

    private List<Seccione> listSecciones;

    @PostConstruct
    public void init() {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        HttpSession httpSession = request.getSession(false);
        if (httpSession != null) {
            Usuario reqdObj = (Usuario) httpSession.getAttribute("UserSession");
            System.out.println("usuario:" + reqdObj.getCuenta());
            if (reqdObj != null) {
                listSecciones = reqdObj.getCliente().getSeccioneList();
            }
        }
    }

    public List<Seccione> getListSecciones() {
        return listSecciones;
    }

    public void setListSecciones(List<Seccione> listSecciones) {
        this.listSecciones = listSecciones;
    }

    public void selectSeccion(Seccione seccion) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            context.getExternalContext().redirect("misdatos.xhtml");
            System.out.println(".............................2");
            HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
            SecurityUtils.setSeccion(request, seccion);
            System.out.println(".............................3");

        } catch (IOException ex) {
            Logger.getLogger(InicioseccionController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
